
package br.edu.utfpr.backuptools.BackupTools.view.telas.principal;

import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;

import br.edu.utfpr.backuptools.BackupTools.controller.validator.RetornoValidacao;
import br.edu.utfpr.backuptools.BackupTools.model.pojo.Backup;
import br.edu.utfpr.backuptools.BackupTools.model.pojo.Configuracao;
import br.edu.utfpr.backuptools.BackupTools.util.Mensagem;
import br.edu.utfpr.backuptools.BackupTools.util.console.Editor;
import br.edu.utfpr.backuptools.BackupTools.util.enums.TipoConexao;
import br.edu.utfpr.backuptools.BackupTools.util.worker.ProgressDialogTask;
import br.edu.utfpr.backuptools.BackupTools.util.worker.WorkerBackup;
import br.edu.utfpr.backuptools.BackupTools.view.action.AbstractAction;
import br.edu.utfpr.backuptools.BackupTools.view.action.AbstractConsultaAction;
import br.edu.utfpr.backuptools.BackupTools.view.action.backup.GerarTodosBackups;
import br.edu.utfpr.backuptools.BackupTools.view.action.backup.ListarBackupAction;
import br.edu.utfpr.backuptools.BackupTools.view.action.backup.SalvarBackupAction;
import br.edu.utfpr.backuptools.BackupTools.view.action.configuracao.ListarConfiguracaoAction;
import br.edu.utfpr.backuptools.BackupTools.view.telas.cadastro.backup.CadastroBackup;
import br.edu.utfpr.backuptools.BackupTools.view.telas.configuracao.ConfiguracaoView;
import br.edu.utfpr.backuptools.BackupTools.view.telas.principal.tabela.BackupCellEditor;
import br.edu.utfpr.backuptools.BackupTools.view.telas.principal.tabela.BackupCellRenderer;
import br.edu.utfpr.backuptools.BackupTools.view.telas.principal.tabela.BackupTableModel;
import br.edu.utfpr.backuptools.BackupTools.view.telas.sobre.Sobre;
/**
 * Janela pricipal da aplicação, contem os componentes de tabela, menus, console e tela de configurações.
 * 
 * @author Luan Malaguti Reffatti
 *
 */
public class JanelaPrincipal extends JFrame {

    AbstractConsultaAction<Configuracao> actionCosultaConf = new ListarConfiguracaoAction();
    AbstractConsultaAction<Backup> actionConsultaBackup = new ListarBackupAction();
    AbstractAction<Backup> actionGerarBackups = new GerarTodosBackups();
    AbstractAction<Backup> actionSalvarBackup = new SalvarBackupAction();
    List<Backup> backups = null;
    Backup selecionado = null;
	
	public JanelaPrincipal() {
		populaTabela();
		initComponents();
        
        setExtendedState(MAXIMIZED_BOTH); 
        setIconImage(new ImageIcon(getClass().getClassLoader().getResource("images/logo.png")).getImage()); 
        
        addLog("Iniciando aplicação...");
    }
	
    /**
     *Metodo responsavel por adicionar logs e atulizar o componente de console
     * 
     * @param log
     */
    public static void addLog(String log){
    	Editor.getInstance().add(log);
        edConsole.setText(Editor.getInstance().getStr());
        edConsole.updateUI();
    }
    
    /**
     * Metodo que popula e atualiza a tabela
     * utilizar este metodo toda vez que modificar algo na tabela
     */
    public void populaTabela(){
    	backups = actionConsultaBackup.execute();

    	if(tabela != null){
    		tabela = new JTable(new BackupTableModel(backups));
            tabela.setDefaultRenderer(Backup.class, new BackupCellRenderer(this));
            tabela.setDefaultEditor(Backup.class, new BackupCellEditor(this));
            tabela.setRowHeight(55);
            
            scrollPaneTabela.setViewportView(tabela);
            
            tabela.updateUI();
            scrollPaneTabela.updateUI();
            panelItems.updateUI();
    	}
    }
    
    /**
     * Metodo que popula e atualiza a tela lateral de configuração
     * utilizar este metodo toda vez que modificar o backup selecionado
     */
    public void populaConfiguracoes(){
   
	    	jtaDescricao.setText(selecionado == null ? "" : selecionado.getDescricao());
	    	edCaminhoOrigem.setText(selecionado == null ? "" : selecionado.getOrigem());
	    	edCaminhoBackup.setText(selecionado == null ? "" : selecionado.getDestino());
	    	if(selecionado == null)
	    	{
	    		jrConexaoLocal.setSelected(true);
	    	}
	    	else{
	    		if(selecionado.getTipoConexao().equals(TipoConexao.REMOTA)){ 
		    		jrConexaoRemota.setSelected(true); 
		    	}
		    	else{
		    		jrConexaoLocal.setSelected(true);
		    	}
	    	}
	    	panelConfiguracao.updateUI();
    	
    }
    
    public void updateSelecionado(Backup backup){
    	selecionado = backup;
    	populaConfiguracoes();
    }
    
    public void showMessage(String texto,int tipo){
    	Mensagem.show(this,texto, tipo);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelConfiguracao = new javax.swing.JInternalFrame();
        lbDescricao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaDescricao = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jrConexaoLocal = new javax.swing.JRadioButton();
        jrConexaoRemota = new javax.swing.JRadioButton();
        lbOrigem = new javax.swing.JLabel();
        edCaminhoOrigem = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        edCaminhoBackup = new javax.swing.JTextField();
        btSelecionarLocalBackup = new javax.swing.JButton();
        btSelecionarOrigem = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        panelItems = new javax.swing.JInternalFrame();
        scrollPaneTabela = new javax.swing.JScrollPane();
       
        panelMenu = new javax.swing.JPanel();
        jbNovo = new javax.swing.JButton();
        jbGerar = new javax.swing.JButton();
        jbSair = new javax.swing.JButton();
        jbParar = new javax.swing.JButton();
        jbSobre = new javax.swing.JButton();
        lbTopo = new javax.swing.JLabel();
        btConfiguracoes = new javax.swing.JButton();
        scrollPaneConsole = new javax.swing.JScrollPane();
        edConsole = new javax.swing.JTextPane();
        radioGrupo = new javax.swing.ButtonGroup();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Backup Tools");

        panelConfiguracao.setTitle("Configuração");
        panelConfiguracao.setPreferredSize(new java.awt.Dimension(300, 600));
        panelConfiguracao.setVisible(true);

        lbDescricao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lbDescricao.setText("Descrição:");

        jtaDescricao.setColumns(20);
        jtaDescricao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jtaDescricao.setRows(5);
        jScrollPane1.setViewportView(jtaDescricao);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Conexão:");

        jrConexaoLocal.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrConexaoLocal.setText("Local");
        jrConexaoLocal.setSelected(true);
        radioGrupo.add(jrConexaoLocal);
        

        jrConexaoRemota.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrConexaoRemota.setText("Remota");
        radioGrupo.add(jrConexaoRemota);

        lbOrigem.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lbOrigem.setText("Caminho de origem:");

        edCaminhoOrigem.setEditable(false);
        edCaminhoOrigem.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Local do backup:");

        edCaminhoBackup.setEditable(false);
        edCaminhoBackup.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        btSelecionarLocalBackup.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btSelecionarLocalBackup.setText("Selecionar");

        btSelecionarOrigem.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btSelecionarOrigem.setText("Selecionar");

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Floppy-Small-icon.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Alarm-Error-icon.png"))); // NOI18N
        btCancelar.setText("Cancelar");
        btCancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelConfiguracaoLayout = new javax.swing.GroupLayout(panelConfiguracao.getContentPane());
        panelConfiguracao.getContentPane().setLayout(panelConfiguracaoLayout);
        panelConfiguracaoLayout.setHorizontalGroup(
            panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConfiguracaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lbOrigem)
                        .addComponent(lbDescricao, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelConfiguracaoLayout.createSequentialGroup()
                        .addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jrConexaoRemota)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrConexaoLocal)
                    .addGroup(panelConfiguracaoLayout.createSequentialGroup()
                        .addComponent(edCaminhoBackup, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btSelecionarLocalBackup))
                    .addGroup(panelConfiguracaoLayout.createSequentialGroup()
                        .addComponent(edCaminhoOrigem, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btSelecionarOrigem)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelConfiguracaoLayout.setVerticalGroup(
            panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConfiguracaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDescricao)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelConfiguracaoLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jrConexaoLocal)
                        .addGap(8, 8, 8)
                        .addComponent(jrConexaoRemota)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelConfiguracaoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addGap(27, 27, 27)))
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbOrigem)
                    .addComponent(btSelecionarOrigem)
                    .addComponent(edCaminhoOrigem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(btSelecionarLocalBackup)
                    .addComponent(edCaminhoBackup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelConfiguracaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btSalvar))
                .addContainerGap())
        );

        panelItems.setTitle("Items ativos");
        panelItems.setPreferredSize(new java.awt.Dimension(924, 600));
        panelItems.setVisible(true);

        scrollPaneTabela.setAutoscrolls(true);

        tabela = new JTable(new BackupTableModel(backups));
        tabela.setDefaultRenderer(Backup.class, new BackupCellRenderer(this));
        tabela.setDefaultEditor(Backup.class, new BackupCellEditor(this));
        tabela.setRowHeight(55);
        
        scrollPaneTabela.setViewportView(tabela);
        

        javax.swing.GroupLayout panelItemsLayout = new javax.swing.GroupLayout(panelItems.getContentPane());
        panelItems.getContentPane().setLayout(panelItemsLayout);
        panelItemsLayout.setHorizontalGroup(
            panelItemsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPaneTabela, javax.swing.GroupLayout.DEFAULT_SIZE, 852, Short.MAX_VALUE)
        );
        panelItemsLayout.setVerticalGroup(
            panelItemsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPaneTabela, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
        );

        panelMenu.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        panelMenu.setForeground(new java.awt.Color(0, 102, 255));

        jbNovo.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Files-New-File-icon.png"))); // NOI18N
        jbNovo.setText("Novo");
        jbNovo.setName("");
        jbNovo.setPreferredSize(new java.awt.Dimension(95, 41));
        jbNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNovoActionPerformed(evt);
            }
        });

        jbGerar.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Play-Normal-icon.png"))); // NOI18N
        jbGerar.setText("Gerar");
        jbGerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGerarActionPerformed(evt);
            }
        });

        jbSair.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Close-icon.png"))); // NOI18N
        jbSair.setText("Sair");
        jbSair.setToolTipText("");
        jbSair.setPreferredSize(new java.awt.Dimension(95, 41));
        jbSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSairActionPerformed(evt);
            }
        });

        jbParar.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Stop-Normal-Red-icon.png"))); // NOI18N
        jbParar.setText("Parar");

        jbSobre.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Help-icon.png"))); // NOI18N
        jbSobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSobreActionPerformed(evt);
            }
        });

        lbTopo.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        lbTopo.setText("Backup Tools");

        btConfiguracoes.setIcon(new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/Settings-icon.png"))); // NOI18N
        btConfiguracoes.setText("Configurações");
        btConfiguracoes.setAlignmentX(0.5F);
        btConfiguracoes.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btConfiguracoes.setPreferredSize(new java.awt.Dimension(95, 41));
        btConfiguracoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConfiguracoesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelMenuLayout = new javax.swing.GroupLayout(panelMenu);
        panelMenu.setLayout(panelMenuLayout);
        panelMenuLayout.setHorizontalGroup(
            panelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMenuLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbGerar, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbParar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btConfiguracoes, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60)
                .addComponent(lbTopo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbSobre, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbSair, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        panelMenuLayout.setVerticalGroup(
            panelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btConfiguracoes, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
            .addGroup(panelMenuLayout.createSequentialGroup()
                .addGroup(panelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jbNovo, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                        .addComponent(jbGerar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbParar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbSobre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbSair, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(lbTopo, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jbGerar.getAccessibleContext().setAccessibleDescription("Gera todos os backups ativos na lista");

        edConsole.setEditable(false);
        scrollPaneConsole.setViewportView(edConsole);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(panelItems, javax.swing.GroupLayout.PREFERRED_SIZE, 868, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(panelConfiguracao, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE))
                    .addComponent(scrollPaneConsole))
                .addContainerGap())
            .addComponent(panelMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelItems, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
                    .addComponent(panelConfiguracao, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollPaneConsole, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        panelConfiguracao.getAccessibleContext().setAccessibleDescription("Configuração");

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void jbGerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGerarActionPerformed
    	String title = "Aguarde";
  		String message = "Gerando rotina de backups, isso pode demorar...";
  		ProgressDialogTask pdt = new ProgressDialogTask(new JFrame(), title, message);
  		WorkerBackup work = new WorkerBackup(null);
  		pdt.setModal(true);
  		pdt.addTask(work);
  		pdt.run();
  		
  		populaTabela();
  		
  		RetornoValidacao rv = work.getRv();
    	Mensagem.show(this,rv.isOk() ? "Rotina de backups executada com sucesso" : rv.getErro(), JOptionPane.INFORMATION_MESSAGE);
    	
    }//GEN-LAST:event_jbGerarActionPerformed

    private void jbSobreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSobreActionPerformed
        new Sobre().setVisible(true);
    }//GEN-LAST:event_jbSobreActionPerformed

    private void jbSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jbSairActionPerformed

    private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoActionPerformed
       new CadastroBackup(this).setVisible(true);
    }//GEN-LAST:event_jbNovoActionPerformed

    private void btConfiguracoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConfiguracoesActionPerformed
    	/**
    	 * Exibe a tela de Configurações ja trazendo a configuração do banco
    	 */
    	new ConfiguracaoView(actionCosultaConf.execute().get(0)).setVisible(true);
    }//GEN-LAST:event_btConfiguracoesActionPerformed

 
   /**
    * Ação do botao salvar da tela de configurações lateral
    */
    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
    	 if(selecionado == null){
    		 Mensagem.show(this, "Nenhum backup selecionado", JOptionPane.INFORMATION_MESSAGE);
    	 }
    	 else{
	    	 selecionado.setDescricao(jtaDescricao.getText());
	    	 selecionado.setOrigem(edCaminhoOrigem.getText());
	    	 selecionado.setDestino(edCaminhoBackup.getText());
	         
	         if(jrConexaoLocal.isSelected())
	        	 selecionado.setTipoConexao(TipoConexao.LOCAL);
	         else if(jrConexaoRemota.isSelected())
	        	 selecionado.setTipoConexao(TipoConexao.REMOTA);
	         
	         RetornoValidacao rv = actionSalvarBackup.execute(selecionado);
	         if(rv.isOk()){
	        	 populaTabela();
	        	 addLog("Backup "+selecionado.getDescricao()+" editado com sucesso");
	         }
    	 }
    }//GEN-LAST:event_btSalvarActionPerformed

    /**
     *  * Ação do botao cancelar da tela de configurações lateral
     */
    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
       populaConfiguracoes(); 
    }//GEN-LAST:event_btCancelarActionPerformed
    
    
    public Class getColumnClass(int columnIndex) { return Backup.class; }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btConfiguracoes;
    private javax.swing.JButton btSalvar;
    private javax.swing.JButton btSelecionarLocalBackup;
    private javax.swing.JButton btSelecionarOrigem;
    private javax.swing.JTextField edCaminhoBackup;
    private javax.swing.JTextField edCaminhoOrigem;
    private static javax.swing.JTextPane edConsole;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbGerar;
    private javax.swing.JButton jbNovo;
    private javax.swing.JButton jbParar;
    private javax.swing.JButton jbSair;
    private javax.swing.JButton jbSobre;
    private javax.swing.JRadioButton jrConexaoLocal;
    private javax.swing.JRadioButton jrConexaoRemota;
    private javax.swing.JTable tabela;
    private javax.swing.JTextArea jtaDescricao;
    private javax.swing.JLabel lbDescricao;
    private javax.swing.JLabel lbOrigem;
    private javax.swing.JLabel lbTopo;
    private javax.swing.JInternalFrame panelConfiguracao;
    private javax.swing.JInternalFrame panelItems;
    private javax.swing.JPanel panelMenu;
    private javax.swing.JScrollPane scrollPaneConsole;
    private javax.swing.JScrollPane scrollPaneTabela;
    private javax.swing.ButtonGroup radioGrupo;
    // End of variables declaration//GEN-END:variables
}
